// 弹窗
// Dialog.confirm({
//     title: '标题',
//     message: '弹窗内容',
//   })
//   .then(() => {
//     // on confirm
//   })
//   .catch(() => {
//     // on cancel
//   });
var util = require("../../utils/util");
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {

    EId:"",
    // 可接订单展示start
    elements: [],
    cId: "",
    description: "",
    skill: "",
    tAddress: "",
    tId: "",
    tStatus: "",
    time: "",

    computer:0,
    printer:0,
    air:0,
    light:0,

    // 每个item的背景颜色
    colorArr: ["#EE2C2C", "#ff7070", "#EEC900", "#4876FF", "#EE2C2C", "#ff7070", "#EEC900", "#4876FF"],
    // 可接订单展示end

    // 底部tabbar start
    tabbar_active: 0,
    tabbar_list: [{
      "url": "../recive_order/recive_order",
      "text": "接单",
      "icon": "todo-list",
      "info": 12,
    }, {
      "url": "../order_list/order_list",
      "text": "订单",
      "icon": "column",
    }, {
      "url": "../personal_info/personal_info",
      "text": "我的",
      "icon": "smile"
    }, {
      "url": "../contact/contact",
      "text": "关于",
      "icon": "phone-circle"
    }],
    // 底部tabbar end

    // 点击查看订单详情start
    "order_more_show": false,

    // 点击查看订单详情end

  },



  /**
   * 点击订单，显示详细信息，方便判断是否接单 start
   */
  click_order(e) {
    var that = this;
    let index = e.currentTarget.dataset.index;
    let column = that.data.elements;
    this.setData({
      skill:column[index].skill,
      tAddress:column[index].tAddress,
      cId:column[index].cId,
      tStatus:column[index].tStatus,
      time:util.formatTime(column[index].time,'M月D日 h:m:s'),
      tId:column[index].tId,
      description:column[index].description,
      order_more_show: true //点击order_item，出现“订单详情”弹窗
    })
  },
  order_more_onClose() {
    this.setData({
      close: false
    }); //点击取消按钮，弹窗隐藏
  },
  //是否申请设备
  order_more_recive() {
    this.setData({
      new_device_show: true
    })
  },
  new_device_close() {
    this.setData({
      close:false
    })
   
  },

  new_device_detials() {
    this.setData({
      new_device_detials_show: true
    })
  },

  new_device_send() {
    var that = this;
    var materials = "";
    if (this.air!=undefined){
      if (materials==""){
          materials=materials+"air:"+this.air
      }
     else materials=materials+","+"air:"+this.air
  }
  if (this.computer!=undefined){
      if (materials==""){
          materials=materials+"computer:"+this.computer
      }
     else materials=materials+","+"computer:"+this.computer
  }
  if (this.light!=undefined){
      if (materials==""){
          materials=materials+"light:"+this.light
      }
     else materials=materials+","+"light:"+this.light
  }
  if (this.printer!=undefined){
      if (materials==""){
          materials=materials+"printer:"+this.printer
      }
    else  materials=materials+","+"printer:"+this.printer
  }
  console.log(materials);
    wx.request({
      url: 'http://localhost:8088/getTaskToDo',
      method:"GET",
      data:{
        TId:this.data.tId,
        EId:this.data.EId,
        material:materials
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success(res){
        var data1 = res.data;
        console.log(data1);
        if("SUCCESS"==data1){
          console.log(res);
          Toast("提交成功");
          console.log(that.data.EId);
          wx.request({
            url: 'http://localhost:8088/getEmployeeTaskToSelect',
            method:"GET",
            data:{
              EId: that.data.EId,
            },
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            success(res){
              console.log(res.data);
              var index = 0;
              var info = 'tabbar_list['+ index + '].info';
              that.setData({
                  elements:res.data,
                  [info]:res.data.length
              })
            }
          });
        }
        else{
          Toast("请勿重复接单");
        }
      }
    })
    this.setData({
      close: false,
      new_device_send_show: true
    }); 
  },

  new_device_send_close() {
    var that = this;
    wx.request({
      url: 'http://localhost:8088/getTaskToDo',
      method:"GET",
      data:{
        TId:this.data.tId,
        EId:this.data.EId,
        material:""
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success(res){
        var data1 = res.data;
        console.log(data1);
        if("SUCCESS"==data1){
          console.log(res);
          Toast("提交成功");
          console.log(that.data.EId);
          wx.request({
            url: 'http://localhost:8088/getEmployeeTaskToSelect',
            method:"GET",
            data:{
              EId: that.data.EId,
            },
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            success(res){
              console.log(res.data);
              var index = 0;
              var info = 'tabbar_list['+ index + '].info';
              that.setData({
                  elements:res.data,
                  [info]:res.data.length
              })
            }
          });
        }
        else{
          Toast("请勿重复接单");
        }
      }
    })
    this.setData({
      close: false,
      new_device_send_show: false
    }); 
  },

  /**
   * 点击订单，显示详细信息，方便判断是否接单 end
   */
printer_change(e){
  var n = Number(e.detail.value);
  this.printer = n;
},

air_change(e){
  var n = Number(e.detail.value);
  console.log(n);
  this.air = n;
  console.log(this.air);
},

computer_change(e){
  var n = Number(e.detail.value);
  this.computer = n;
},

light_change(e){
  var n = Number(e.detail.value);
  this.light = n;
},
  /**
   * tabbar start
   */

  tabbar_onChange: function (res) {
    this.setData({
      tabbar_active: res.detail
    });
    // console.log(this.data.tabbar_list[res.detail].url);
    console.log(this.data.EId);
    wx.navigateTo({
      url: this.data.tabbar_list[res.detail].url+"?Id="+this.data.EId,
    });
  },

  /**
   * tabbar end
   */

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      EId:options.Id
    })
    const that = this;
    console.log(options.Id);
    console.log(this.data.EId);
    wx.request({
      url: 'http://localhost:8088/getEmployeeTaskToSelect',
      method:"GET",
      data:{
        EId: this.data.EId,
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success(res){
        console.log(res.data);
        var index = 0;
        var info = 'tabbar_list['+ index + '].info';
        that.setData({
            elements:res.data,
            [info]:res.data.length
        })
      }
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})